<?php
//接收当前页
$page = isset($_GET['page'])?$_GET['page']:1;
//设置每页显示条数
$size = 6;
$html_list = "page/$page.html";
ob_start();
//连接数据库
$dbh = new PDO('mysql:host=127.0.0.1;dbname=1105', "root", "root");
//查询的sql语句
$sql = "select * from news";
//执行sql语句
$stmtname = $dbh->query($sql);
//计算总条数
$total = $stmtname->rowCount();
//计算偏移量
$limit = ($page-1)*$size;
//查询数据
$sql1 = "select * from news limit $limit,$size";
//执行sql语句
$stmt = $dbh->query($sql1);
//返回数组格式
$data = $stmt->fetchAll(2);
//判断是否查询成功
if($data){
    $arr['code'] = 0;
    $arr['msg'] = 'ok';
    $arr['data'] = $data;
    $arr['total'] = $total;
}else{
    $arr['code'] = 1;
    $arr['msg'] = 'no';
    $arr['data'] = [];
}
$data = ob_get_contents();
file_put_contents("page/$page.html",$data);
//返回json格式的数据
echo json_encode($arr);

